<fieldset class="layui-elem-field">
    <form class="layui-form" id="searchForm">
        <e>数据库中共有 <b>{$result.tableNum}</b> 张表，共计 <b>{$result.total}</b> </e>
    </form>
</fieldset>
<table class="layui-hide" id="mytable" lay-filter="mytable"></table>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="backUp">备份</button>
        <button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="optimize">优化</button>
        <button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="repair">修复</button>
    </div>
</script>
<script type="text/javascript">
    $(function(){
        ybTable.render({
            elem: '#mytable'
            ,url: "{:url('getDataList')}"
            ,where: searchParamObj('searchForm')
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,title: '数据表'
            ,cols: [[
                {field:'name', type: 'checkbox', fixed: 'left'}
                ,{field:'name', title: '数据库表'}
                ,{field:'rows', title: '记录条数'}
                ,{field:'size', title: '占用空间'}
                ,{field:'engine', title: '类型'}
                ,{field:'collation', title: '编码'}
                ,{field:'create_time', title: '创建时间'}
                ,{field:'comment', title: '说明'}
            ]]
            ,page: false
            ,response: {
                statusCode: 1 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.dataList //解析数据列表
                };
            }
        });

        //头工具栏事件
        ybTable.on('toolbar(mytable)', function(obj){
            switch(obj.event){
                case 'backUp':
                    var checkStatus = ybTable.checkStatus('mytable'),data = checkStatus.data;
                    if(data.length == 0){
                        ybLayer.msg('请选择需要操作的数据');
                        return false;
                    }
                    var ids = [];
                    for (var i= 0; i<data.length; i++){
                        ids.push(data[i].name)
                    }
                    ajaxPost("{:url('backup')}",{'ids':ids},function(res){
                        ybLayer.msg(res.msg,{icon: 6});
                        setTimeout(function () {
                            ybTable.reload('mytable');
                        }, 1000);
                    },function(res){
                        ybLayer.msg(res.msg,{icon: 5});
                    })
                    break;
                case 'optimize':
                    var checkStatus = ybTable.checkStatus('mytable'),data = checkStatus.data;
                    if(data.length == 0){
                        ybLayer.msg('请选择需要操作的数据');
                        return false;
                    }
                    var ids = [];
                    for (var i= 0; i<data.length; i++){
                        ids.push(data[i].name)
                    }
                    ajaxPost("{:url('optimize')}",{'ids':ids},function(res){
                        ybLayer.msg(res.msg,{icon: 6});
                        setTimeout(function () {
                            ybTable.reload('mytable');
                        }, 1000);
                    },function(res){
                        ybLayer.msg(res.msg,{icon: 5});
                    })
                    break;
                case 'repair':
                    var checkStatus = ybTable.checkStatus('mytable'),data = checkStatus.data;
                    if(data.length == 0){
                        ybLayer.msg('请选择需要操作的数据');
                        return false;
                    }
                    var ids = [];
                    for (var i= 0; i<data.length; i++){
                        ids.push(data[i].name)
                    }
                    ajaxPost("{:url('repair')}",{'ids':ids},function(res){
                        ybLayer.msg(res.msg,{icon: 6});
                        setTimeout(function () {
                            ybTable.reload('mytable');
                        }, 1000);
                    },function(res){
                        ybLayer.msg(res.msg,{icon: 5});
                    })
                    break;
            }
        });

    })
</script>